<template>
	<view>
		<nav-bar color="#000000" bgc="#F4F4FA" bbtn>支付</nav-bar>
		<view class="amount-title">
			支付金额
		</view>
		<view class="amount">￥{{amount}}</view>
		<view class="pay-type">支付方式：<text>微信支付</text></view>
		<view class="btn" @click="pay">立即支付</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				amount: 0,
				type:1,
			};
		},
		methods:{
			pay(){
				this.ajaxJson('payment', {orderId: this.id}, res => {
					//调起支付
						let options = res
					WeixinJSBridge.invoke(
					            'getBrandWCPayRequest', {
					              "appId": options.appId, //公众号名称，由商户传入     
					              "timeStamp": options.timeStamp, //时间戳，自1970年以来的秒数     
					              "nonceStr": options.nonceStr, //随机串     
					              "package": options.package,
					              "signType": "MD5", //微信签名方式：     
					              "paySign": options.sign //微信签名 
					            },
					            function(res) {
					              if (res.err_msg == "get_brand_wcpay_request:ok") {
					                // 使用以上方式判断前端返回,微信团队郑重提示：
					                //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
									uni.navigateTo({
										url:'../pay/successPay?order_id='+this.id+'&type='+this.type
									})
					              }else{
									  
								  }
					            });
				});
			}
		},
		onLoad(options) {
			this.id = options.id//订单id
			this.amount = options.amount//订单金额
			this.type = options.type  //商品；类型 1券码2物流
		}
	}
</script>

<style lang="scss">
	nav-bar,page{
		background: #F4F4FA;
	}
.amount-title{
	margin: 235rpx 0 48rpx;
	font-size:32rpx;
	color:rgba(170,170,170,1);
	line-height: 1;
	text-align: center;
}
.amount{
	font-size:88rpx;
	font-family:PingFang SC;
	font-weight:bold;
	color:rgba(29,30,33,1);
	line-height: 1;
	text-align: center;
	margin-bottom: 69rpx;
}
.pay-type{
	margin-left: 89rpx;
	margin-bottom: 70rpx;
	text-align: left;
	font-size:28rpx;
	font-family:PingFang SC;
	font-weight:500;
	color:rgba(29,30,33,1);
	line-height: 1;
	text{
		font-size:28rpx;
		font-family:PingFang SC;
		font-weight:500;
		color:rgba(254,113,70,1);
		line-height: 1;
		
	}
}
.btn{
	width:600rpx;
	height:88rpx;
	background:linear-gradient(90deg,rgba(253,100,49,1),rgba(255,153,114,1));
	box-shadow:0px 1px 20rpx 0px rgba(185,51,6,0.3);
	border-radius:44rpx;
	margin: 0 auto;
	font-size:36rpx;
	font-family:PingFang SC;
	font-weight:bold;
	color:rgba(255,255,255,1);
	line-height: 88rpx;
	text-align: center;
}
</style>
